<?php

	// +----------------------------------------------------------------------
	// | 属性模型
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace app\model\cms;

	class Attribute extends Common
	{

		public $type_list = [
			'number' => ['数字', 'int(10) UNSIGNED NOT NULL'],
			'hidden' => ['隐藏', 'int(10) UNSIGNED NOT NULL'],
			'string' => ['字符串', 'varchar(255) NOT NULL'],
			'textarea' => ['文本框', 'text NOT NULL'],
			'date' => ['日期', 'int(10) NOT NULL'],
			'datetime' => ['时间', 'int(10) NOT NULL'],
			'bool' => ['布尔', 'tinyint(2) NOT NULL'],
			'select' => ['枚举', 'char(50) NOT NULL'],
			'radio' => ['单选', 'char(10) NOT NULL'],
			'checkbox' => ['多选', 'varchar(100) NOT NULL'],
			'editor' => ['编辑器', 'text NOT NULL'],
			'image' => ['单个图片', 'varchar(255) NOT NULL'],
			'attachment' => ['单个附件', 'varchar(255) NOT NULL'],
			'hasone' => ['一对一标签', '一对一标签，直接输入标签名，需要builder支持'],
		];
		//无需添加字段
		public $no_add_field_type = ['hasone'];
		public $is_show_list = [0 => '不显示', 1 => '始终显示', 2 => '新增显示', 3 => '编辑显示', 5 => '隐藏表单'];
		public $is_must_list = ['否', '是'];

		public $validate_type_list = [
			'regex' => '正则验证',
			'function' => '函数验证',
			'unique' => '唯一验证',
			'length' => '长度验证',
			'between' => '区间验证',
			'notbetween' => '不在区间验证',
			'in' => '验证在范围内',
			'notin' => '验证不在范围内',
		];

		public $auto_type_list = ['function' => '函数', 'field' => '字段', 'string' => '字符串'];
		public $validate_time_list = ['1' => '新 增', '2' => '编 辑', '3' => '始 终'];
		public $auto_time_list = ['1' => '新 增', '2' => '编 辑', '3' => '始 终'];

		/**
		 * 根据模型id获取字段属性name集
		 * @param integer $pattern_id
		 * @return array
		 */
		public static function getNamesByModel($pattern_id)
		{
			return self::where('pattern_id', $pattern_id)->column('name');
		}


		/**
		 * 写入修改
		 * @param $data
		 */
		public static function onBeforeInsert($data)
		{
			$data['status'] = 1;
		}

	}
